package com.dede.rxbase.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.dede.rxbase.dialog.StateDialog;
import com.dede.rxbase.dialog.StateDialogHelper;

/**
 * 包含状态切换的Activity
 * Created by dede on 2018/2/27.
 */
public abstract class BaseStateActivity extends BaseActivity implements View.OnClickListener {

    private StateDialogHelper helper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        helper = new StateDialogHelper(this);
        super.onCreate(savedInstanceState);
    }

    /**
     * 初始化错误Dialog
     *
     * @return
     */
    @Nullable
    public StateDialog createErrorDialog() {
        return null;
    }

    /**
     * 初始化LoadingDialog
     *
     * @return
     */
    @Nullable
    public StateDialog createLoadingDialog() {
        return null;
    }

    /**
     * 初始化无数据Dialog
     *
     * @return
     */
    @Nullable
    public StateDialog createEmptyDialog() {
        return null;
    }

    /**
     * 显示错误Dialog
     */
    public void showError() {
        helper.showError();
    }

    /**
     * 显示LoadingDialog
     */
    public void showLoading() {
        helper.showLoading();
    }

    /**
     * 显示无数据Dialog
     */
    public void showEmpty() {
        helper.showEmpty();
    }

    /**
     * 隐藏所有的Dialog
     */
    public void hideLoading() {
        helper.hideLoading();
    }

    /**
     * 重新加载数据
     */
    protected void reload() {
        initData();
    }

    @Override
    public void onClick(View v) {
        if (helper.getState() <= StateDialog.EMPTY) {
            reload();
        }
    }
}
